package com.yanfan.parking;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.ibms.common.utils.HttpUtils2;
import com.yanfan.parking.domain.NjCarWhiteInfo;
import com.yanfan.parking.domain.NjParkingCarInfo;
import com.yanfan.parking.domain.NjParkingDeviceInfo;
import com.yanfan.parking.domain.NjParkingHourFlow;
import com.yanfan.parking.utils.OauthUtil;
import org.junit.jupiter.api.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class Main {

    @Test
    public void getAlarmStatus() throws Exception {
        String publicKey = OauthUtil.getPublicKey();
        String accessToken = OauthUtil.accessToken(publicKey);
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization","bearer " + accessToken);
        HashMap<String, Object> param = new HashMap<>();
        param.put("pageNum",1);
        param.put("pageSize",9999);
        JSONObject jsonObject = HttpUtils2.
                sendSLLGetParm(
                        "https://192.168.254.6:443/evo-apigw/ipms/car/list"
                        ,headers,param);
        List<NjParkingCarInfo> carList = JSON.parseArray(JSONObject.parseObject(jsonObject.
                get("data").toString()).get("pageData").toString(), NjParkingCarInfo.class);


    }

    /**
     * 门禁设备
     * @throws Exception
     */
    @Test
    public void getParkingDevice() throws Exception {
        String publicKey = OauthUtil.getPublicKey();
        String accessToken = OauthUtil.accessToken(publicKey);
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization","bearer " + accessToken);
        HashMap<String, Object> param = new HashMap<>();
        param.put("pageNum",1);
        param.put("pageSize",9999);
        JSONObject jsonObject = HttpUtils2.
                sendSLLGetParm(
                        "https://192.168.254.6:443/evo-apigw/ipms/device/list"
                        ,headers,param);

        List<Object> deviceList = JSON.parseArray(JSONObject.parseObject(jsonObject.
                get("data").toString()).get("pageData").toString(), NjParkingDeviceInfo.class);
        System.out.println(deviceList);


    }

    @Test
    public void getParkingChannel() throws Exception {
        String publicKey = OauthUtil.getPublicKey();
        String accessToken = OauthUtil.accessToken(publicKey);
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization","bearer " + accessToken);
        HashMap<String, Object> param = new HashMap<>();
        param.put("pageNum",1);
        param.put("pageSize",9999);
        JSONObject jsonObject = HttpUtils2.
                sendSLLGetParm(
                        "https://192.168.254.6:443/evo-apigw/ipms/device/sluice/channel"
                        ,headers,null);

        JSONArray jsonArray = JSON.parseArray(JSONObject.parseObject(jsonObject.
                get("data").toString()).get("pageData").toString());
        System.out.println(jsonArray);


    }

    /**
     * 获取车场信息
     * @throws Exception
     */
    @Test
    public void getParkinglot() throws Exception {
        String publicKey = OauthUtil.getPublicKey();
        String accessToken = OauthUtil.accessToken(publicKey);
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization","bearer " + accessToken);
        HashMap<String, Object> param = new HashMap<>();
        param.put("pageNum",1);
        param.put("pageSize",9999);
        param.put("returnPage",1);
        JSONObject jsonObject = HttpUtils2.
                sendSLLGetParm(
                        "https://192.168.254.6:443/evo-apigw/ipms/parkinglot/query"
                        ,headers,param);

        JSONArray jsonArray = JSON.parseArray(JSONObject.parseObject(jsonObject.
                get("data").toString()).get("pageData").toString());
        //  1001
        System.out.println(jsonArray);


    }

    /**
     * 场区绑定车位
     * @throws Exception
     */
    @Test
    public void getByParkCode() throws Exception {
        String publicKey = OauthUtil.getPublicKey();
        String accessToken = OauthUtil.accessToken(publicKey);
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization","bearer " + accessToken);
        HashMap<String, Object> param = new HashMap<>();
        param.put("parkinglotCode","1001");
        //param.put("pageSize",9999);
        JSONObject jsonObject = HttpUtils2.
                sendSLLGetParm(
                        "https://192.168.254.6:443/evo-apigw/ipms/carport/getByParkCode"
                        ,headers,param);

        JSONArray jsonArray = JSON.parseArray(JSONObject.parseObject(jsonObject.
                get("data").toString()).get("pageData").toString());
        System.out.println(jsonArray);


    }

    /**
     * 车位实时在停信息查询
     * @throws Exception
     */
    @Test
    public void getCarPort() throws Exception {
        String publicKey = OauthUtil.getPublicKey();
        String accessToken = OauthUtil.accessToken(publicKey);
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization","bearer " + accessToken);
        HashMap<String, Object> param = new HashMap<>();
        param.put("pageNum","1001");
        param.put("pageSize",9999);
        JSONObject jsonObject = HttpUtils2.
                sendSLLGetParm(
                        "https://192.168.254.6:443/evo-apigw/ipms/carport/list"
                        ,headers,param);

        JSONArray jsonArray = JSON.parseArray(JSONObject.parseObject(jsonObject.
                get("data").toString()).get("pageData").toString());
        System.out.println(jsonArray);


    }

    /**
     * 停车场黑白名单
     * @throws Exception
     */
    @Test
    public void getcarWhiteList() throws Exception {
        String publicKey = OauthUtil.getPublicKey();
        String accessToken = OauthUtil.accessToken(publicKey);
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization","bearer " + accessToken);
        HashMap<String, Object> param = new HashMap<>();
        param.put("pageNum","1");
        param.put("pageSize",9999);
        JSONObject jsonObject = HttpUtils2.
                sendSLLGetParm(
                        "https://192.168.254.6:443/evo-apigw/ipms/carWhiteList/sendCars"
                        ,headers,param);
        List<NjCarWhiteInfo> list = JSON.parseArray(JSONObject.parseObject(jsonObject.
                        get("data").toString()).get("pageData").toString(),
                NjCarWhiteInfo.class);
        System.out.println(list);


    }

    /**
     * 车流统计
     * @throws Exception
     */
    @Test
    public void getParkSurvey() throws Exception {
        String publicKey = OauthUtil.getPublicKey();
        String accessToken = OauthUtil.accessToken(publicKey);
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization","bearer " + accessToken);
        HashMap<String, Object> param = new HashMap<>();
        param.put("pageNum","1");
        param.put("pageSize",9999);
        JSONObject jsonObject = HttpUtils2.
                sendSLLGetParm(
                        "https://192.168.254.6:443/evo-apigw/ipms/parkSurvey/carInOutSurvey?type=0"
                        ,headers,null);
        List<NjParkingHourFlow> parseArray = JSON.parseArray(JSONObject.parseObject(jsonObject.get("data").toString())
                .get("carInoutTrend").toString(), NjParkingHourFlow.class);
        System.out.println(parseArray);


    }

    @Test
    public void dateTest(){
        String dateToStr = DateUtils.parseDateToStr("yyyyMMdd", new Date());
        System.out.println(dateToStr);
    }
}
